package com.slkj.shilixiaoyuanapp.view.dialog;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.TextView;

import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.view.base.BaseBottomDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import yanzhikai.ruler.BooheeRuler;
import yanzhikai.ruler.RulerCallback;

/**
 * Created  on 2018-09-13
 *
 * @author 唐开阔
 * @describe 卷尺dialog
 */
public class BooheeRulerDialog extends BaseBottomDialog {


    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_sure)
    TextView tvSure;
    @BindView(R.id.tv_num)
    TextView tvNum;
    @BindView(R.id.br_top_head)
    BooheeRuler brTopHead;
    CallBack callBack;
    float num = 60;
    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setCancelable(false);
    }

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_boohee_ruler;
    }

    public void setNum(int num) {
        this.num = num;


    }



    @Override
    public void onResume() {
        super.onResume();

    }

    @Override
    public void bindView() {
        brTopHead.setCallback(scale -> {
            num = (int)scale;
            tvNum.setText(String.valueOf(num));
        });
    }
    @OnClick(R.id.tv_cancel) void cancel(){
        dismiss();
    }

    @OnClick(R.id.tv_sure) void sure(){
        if (callBack != null){
            callBack.back(num);
        }
        dismiss();
    }

    public interface CallBack{
        void back(float num);
    }

    public void show(int num,FragmentManager fragmentManager) {
        this.num = num;
        super.show(fragmentManager);

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        callBack = null;
    }
}
